package com.zhaopin.mianshi;

/**
 * @author yin.peide
 * @date 2021-05-10 11:12
 */
public class Volatile {

    private static  int count = 0;

    public static void main(String[] args) throws InterruptedException {
        //开启10个线程，分别对count进行自增操作
        for (int i = 0; i < 10; i++) {
            Thread thread = new Thread(() -> {
                for (int j = 0; j < 5000; j++) {
                    synchronized (Volatile.class){
                        count++;    //先读，再加，不是一个原子操作
                    }
                }
            });
            thread.start();
        }
        Thread.sleep(2000);

        System.out.println("count==" + count);
    }

}
